package com.hikari.cloud.base.rabbitmq;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class FirstDirectSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     *
     * @param uuid
     * @param message 消息
     */
    public void send(String uuid, Object message) {
        CorrelationData correlationId = new CorrelationData(uuid);
        /**
         * ExchangeConfig.DIRECT_EXCHANGE  指定消息交换机
         * RabbitMqConfig.ROUTIN_DIRECT_KEY  指定路由键
         */
        //发送消息至：direct类型的交互机【RabbitMqConfig.DIRECT_EXCHANGE】上，路由键是【RabbitMqConfig.ROUTIN_DIRECT_KEY】
        rabbitTemplate.convertAndSend(ExchangeConfig.DIRECT_EXCHANGE, RabbitMqConfig.ROUTIN_DIRECT_KEY,
                message, correlationId);
    }

}